﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Register.IDAL;
using Register.DBUtility;
using System.Data.SqlClient;
using System.Data;
using Register.Model;

namespace Register.DAL
{
    /// <summary>
    /// FileName: EvaluationInfoDAL.cs
    /// CLRVersion: 4.0.30319.269
    /// Author: WangKungLun
    /// Corporation: 
    /// Description: 
    /// DateTime: 2012/7/9 10:07:20
    /// </summary>
    public class EvaluationInfoDAL : IEvaluationInfoDAL
    {
        private string tableName = "System_evaluationInfo";


        public List<Model.EvaluationInfo> GetPagedEvaluationInfo(int size, int pageIndex, string where)
        {
            return DataSetToList(DbHelperSQL.getPagedData(" * ", " EvaluationInfo_AddTime ", where, tableName, OrderBy.DESC, pageIndex, size));
        }

        private List<Model.EvaluationInfo> DataSetToList(DataSet ds)
        {
            List<Model.EvaluationInfo> list = new List<Model.EvaluationInfo>();
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                EvaluationInfo evaluationInfo = new EvaluationInfo();
                evaluationInfo.EvaluationInfo_ID = (String)dr["EvaluationInfo_ID"];
                evaluationInfo.Doctor_ID = (String)dr["Doctor_ID"];
                evaluationInfo.PatientUserInfo_ID = (String)dr["PatientUserInfo_ID"];
                evaluationInfo.EvaluationInfo_EvalWay = (String)dr["EvaluationInfo_EvalWay"];
                evaluationInfo.EvaluationInfo_AddTime = (DateTime)dr["EvaluationInfo_AddTime"];
                evaluationInfo.EvaluationInfo_EvalContent = (String)dr["EvaluationInfo_EvalContent"];
                evaluationInfo.EvaluationInfo_Status = (String)dr["EvaluationInfo_Status"];
                list.Add(evaluationInfo);
            }
            return list;
        }
        public int GetEvaluationInfoCount(string where)
        {
            int count = 0;
            StringBuilder str = new StringBuilder();
            str.Append(" select count(*) from ");
            str.Append(tableName);
            if (where != null)
            {
                str.Append(" where ");
                str.Append(where);
                count = (int)DbHelperSQL.GetSingle(str.ToString());
            }
            else
            {
                count = (int)DbHelperSQL.GetSingle(str.ToString());
            }
            return count;
        }
    }
}
